const http = require('http')
const fs = require('fs')


const server = http.createServer((req,res)=>{
    let url = req.url.toLowerCase()
    res.setHeader("Content-type","text/html;charset=utf-8")


   if( url ==='/' || url ==='/index'){
    let content = fs.readFileSync('./index.html','utf8')
    res.end(content)
   }else if(url ==='/inde.css'){
    res.setHeader("Content-type","text/css;charset=utf-8")
    let content =fs.readFileSync('./css/inde.css','utf8')
    res.end(content)

   }else if(url ==='/dot.png'){
    res.setHeader("Content-type","image/png")
    let content = fs.readFileSync('./image/dot.png')
        res.end(content)

   }else if(url ==='/avatar.png'){
    res.setHeader("Content-type","image/png")
    let content = fs.readFileSync('./image/avatar.png')
        res.end(content)
    }else if(url ==='/dot.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/dot.png')
            res.end(content)
    }else if(url ==='/happy.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/happy.png')
        res.end(content)
    }else if(url ==='/banner.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/banner.png')
        res.end(content)
    }else if(url ==='/lesson.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/lesson.png')
        res.end(content)
    }else if(url ==='/logo.png'){
        res.setHeader("Content-type","application/x-png")
        let content = fs.readFileSync('./image/logo.png')
        res.end(content)
    }else if(url ==='/new.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/new.png')
        res.end(content)
    }else if(url ==='/php.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/php.png')
        res.end(content)
    }else if(url ==='/search.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/search.png')
        res.end(content)
    }else if(url ==='/hot.png'){
        res.setHeader("Content-type","image/png")
        let content = fs.readFileSync('./image/hot.png')
        res.end(content)
        
        
    }  else {
        res.statusCode = 404;
        let content = fs.readFileSync('./404.html','utf8')
        res.end(content)
     }
})
server.listen(8600,()=>{
    console.log('服务已经启动 端口 8600')
})